package com.article;

import com.article.config.PublicConfig;
import com.article.model.ArticleInfo;
import com.article.model.ArticleType;
import com.article.service.ArticleInfoService;
import com.article.service.ArticleTypeService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import java.util.List;

/**
 * Created by Administrator on 2017/4/28.
 */
@Component
public class ContextLoaderInit implements ServletContextListener, ApplicationContextAware {

    private static ApplicationContext applicationContext;

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        this.applicationContext = applicationContext;
    }

    public void contextInitialized(ServletContextEvent servletContextEvent) {
        ServletContext application = servletContextEvent.getServletContext();
        // 设置全局参数
        application.setAttribute("IS_SSL", PublicConfig.IS_SSL);
        // 门户URL地址
        application.setAttribute("PROTAL_URL", PublicConfig.PROTAL_URL);
        // 公司信息
        application.setAttribute("COMPANY_NAME", PublicConfig.COMPANY_NAME);
        application.setAttribute("COMPANY_FOR", PublicConfig.COMPANY_FOR);
        application.setAttribute("COMPANY_LOGO", PublicConfig.COMPANY_LOGO);
        application.setAttribute("COMPANY_TEL", PublicConfig.COMPANY_TEL);
        application.setAttribute("COMPANY_ADDRESS", PublicConfig.COMPANY_ADDRESS);
        application.setAttribute("COMPANY_EMAIL", PublicConfig.COMPANY_EMAIL);
        application.setAttribute("COMPANY_NET_ICP", PublicConfig.COMPANY_NET_ICP);
        application.setAttribute("COMPANY_HR_EMAIL", PublicConfig.COMPANY_HR_EMAIL);
        //是否 是 域名 + 应用名
        application.setAttribute("IS_USE_DOMAIN_NAME", PublicConfig.IS_USE_DOMAIN_NAME);
        application.setAttribute("FILE_SYS_URL", PublicConfig.FILE_SYS_URL);
    }

    public void contextDestroyed(ServletContextEvent servletContextEvent) {

    }
}
